package net.openvision.music.composition;

import net.openvision.music.model.Length;

public class Element {
	public static final int UNDEFINED = -1;

	private MultiSequence sequence;
	private int index;
	private double weight;
	private Length length;
	private ElementValue value;

	Element(ElementValue value, double weight, Length length,
			MultiSequence sequence, int index) {
		this.value = value;
		this.weight = weight;
		this.length = length;
		this.index = index;
		this.sequence = sequence;
	}

	public Element setValue(ElementValue newValue) {
		return new Element(newValue, weight, length, sequence, index);
	}

	public ElementValue getValue() {
		return value;
	}
	
	public byte get(int index) {
		return value.getValue(index);
	}

	public int getSize() {
		return value.getSize();
	}

	public double getWeight() {
		return weight;
	}

	public Length getLength() {
		return length;
	}

	int getIndex() {
		return index;
	}

	@Override
	public boolean equals(Object o) {
		if (!(o instanceof Element))
			return false;
		Element e = (Element) o;
		return weight == e.weight && length.equals(e.length)
				&& value.equals(e.value);
	}

	@Override
	public int hashCode() {
		int hc = value.hashCode();
		hc += length.hashCode();
		hc += ((Double) weight).hashCode();
		return hc;
	}
}
